package com.laoxu.microservice.orderservice.service;

import com.laoxu.microservice.orderservice.pojo.Product;
import com.laoxu.microservice.orderservice.properties.OrderProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @description: 商品服务
 * @author: luohanye
 * @create: 2019-10-20
 **/
@Service
public class ProductService {
    // Spring框架对RESTful方式的http请求做了封装，来简化操作
    @Autowired
    private RestTemplate restTemplate;

    /*@Value("{services.product-service.url}")
    private String productServiceUrl;*/

    @Autowired
    private OrderProperties orderProperties;

    public Product queryProductById(Long id) {
        return this.restTemplate.getForObject(orderProperties.getProductService().getUrl()
                + id, Product.class);
    }
}
